package com.naiterui.ehp.bs.wechat.param.custom;

import com.naiterui.ehp.bs.wechat.constants.WeChatConstant;
import com.naiterui.ehp.bs.wechat.protocol.msg.custom.CustomMiniProgram;
import com.naiterui.ehp.bs.wechat.protocol.msg.custom.CustomMsg;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

/**
 * 小程序卡片
 *
 * @author zhoupeipei
 * @date 2019-07-05 14:58
 * @since 1.0.0
 */
@Data
public class MiniProgramMsgParam extends BaseCustomParam {
    private static final long serialVersionUID = -4181934506278706426L;
    /**
     * 标题
     */
    private String titile;
    /**
     * 小程序appid
     */
    private String appId;
    /**
     * 小程序路径
     */
    private String pagePath;
    /**
     * 缩略图/小程序卡片图片的媒体ID，小程序卡片图片建议大小为520*416</p>
     * <p>【临时素材】通过IMediaApiService.uploadTempMedia上传获得</p>
     * <p>【永久素材】通过IMediaApiService.uploadMedia上传所得</p>
     */
    private String thumbMediaId;

    /**
     * @param openId
     * @param titile       标题
     * @param appId        小程序appid
     * @param pagePath     小程序路径
     * @param thumbMediaId 图片文件在微信服务器上的id
     *                     <p>【临时素材】通过IMediaApiService.uploadTempMedia上传获得</p>
     *                     <p>【永久素材】通过IMediaApiService.uploadMedia上传所得</p>
     */
    public MiniProgramMsgParam(String openId, String titile, String appId, String pagePath, String thumbMediaId) {
        super.setOpenId(openId);
        super.setMsgType(WeChatConstant.KefuMsgType.MINIPROGRAMPAGE);
        this.setTitile(titile);
        this.setAppId(appId);
        this.setPagePath(pagePath);
        this.setThumbMediaId(thumbMediaId);
    }

    @Override
    public CustomMsg getCustomProtocol() {
        if (super.validate() && StringUtils.isNotBlank(titile)
                && StringUtils.isNotBlank(appId)
                && StringUtils.isNotBlank(pagePath)
                && StringUtils.isNotBlank(thumbMediaId)) {
            CustomMiniProgram customMiniProgram = new CustomMiniProgram(titile, appId, pagePath, thumbMediaId);
            return new CustomMsg(getOpenId(), customMiniProgram, getMsgType());
        }
        return null;
    }
}
